#!/usr/bin/env/python3.7
# -*- coding: utf-8 -*-

"""
@File    : download_audio.py
@Time    : 12/02/2021
@Author  : Silence
@Version : 1.0
@Contact : silence2021silence@163.com
@License : (C)Copyright 2021-2021, Silence
@Desc    : None
"""

import pymysql
import datetime

database = pymysql.connect(host="120.24.51.156", user="dormitory_system", password="123456",
                                    database="dormitory_system", charset="utf8")

class Audio_Data():
    def download():
        cursor_2 = database.cursor(cursor=pymysql.cursors.DictCursor)
        sql_2 = """
                    select
        	            audio_file_name, audio_file_data, audio_file_type
                    from
        	            admin_audio_message

                    """
        cursor_2.execute(sql_2)
        audio_file = cursor_2.fetchall()
        for data in audio_file:
            file_name = data["audio_file_name"]
            file_data = data["audio_file_data"]
            file_type = data["audio_file_type"]
        with open("./download_audio/" + file_name + "." + file_type, "wb") as f:
            f.write(file_data)
        cursor_2.close()
        database.close()



if __name__ == '__main__':
    Audio_Data.download()